{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "aa23f053",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.35cf94d45f2725547aeb1c06cf1a1201.315360000.1964332988.282335-25863376', 'expires_in': 2592000, 'session_key': '9mzdDFDeep6Ki2xIwsR92ZEyERU3BMzR1sPit6sjeNsbmMZaEGgT6WsW+L8+pKM14/y8M44uurODqEosost/vA95dj3WaQ==', 'access_token': '24.7e5a0c643b744d672541254c5e740f68.2592000.1651564988.282335-25863376', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online', 'session_secret': '2d33366aae0be32cc510905a35df869b'}\n"
     ]
    }
   ],
   "source": [
    "import requests \n",
    "host = \"https://aip.baidubce.com/oauth/2.0/token\"\n",
    "payload = {\n",
    "    \"grant_type\":\"client_credentials\",\n",
    "    \"client_id\":\"BZNftuKFBvGPVxfrU94xwMG3\",\n",
    "    \"client_secret\":\"Z0bP3Ss2sSAFihGjoGxVDBymvH8xp2TR\"\n",
    "}\n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2c6f39e1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'refresh_token': '25.35cf94d45f2725547aeb1c06cf1a1201.315360000.1964332988.282335-25863376',\n",
       " 'expires_in': 2592000,\n",
       " 'session_key': '9mzdDFDeep6Ki2xIwsR92ZEyERU3BMzR1sPit6sjeNsbmMZaEGgT6WsW+L8+pKM14/y8M44uurODqEosost/vA95dj3WaQ==',\n",
       " 'access_token': '24.7e5a0c643b744d672541254c5e740f68.2592000.1651564988.282335-25863376',\n",
       " 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online',\n",
       " 'session_secret': '2d33366aae0be32cc510905a35df869b'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "aef6619c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.7e5a0c643b744d672541254c5e740f68.2592000.1651564988.282335-25863376'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shena_AT = response.json()[\"access_token\"]\n",
    "shena_AT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a3ef9940",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': [{'name': '郁金香', 'score': 0.80657005, 'baike_info': {'baike_url': 'http://baike.baidu.com/item/%E9%83%81%E9%87%91%E9%A6%99/13506', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/ca1349540923dd54564eae779c46a4de9c82d158e2d7', 'description': \"郁金香(学名：Tulipa gesneriana L.)是百合科郁金香属的多年生草本植物，具鳞茎。英文名为“Didier's tulip”或“Garden tulip”。叶3-5枚，条状披针形至卵状披针状，花单朵顶生，大型而艳丽，花被片红色或杂有白色和黄色，有时为白色或黄色，长5-7厘米，宽2-4厘米，6枚雄蕊等长，花丝无毛，无花柱，柱头增大呈鸡冠状，花期4-5月。郁金香原产中国古代西域及西藏新疆一带，是土耳其、荷兰、匈牙利等国的国花。\"}}, {'name': '郁金', 'score': 0.0083072595, 'baike_info': {}}, {'name': '网球花', 'score': 0.004648656, 'baike_info': {'baike_url': 'http://baike.baidu.com/item/%E7%BD%91%E7%90%83%E8%8A%B1/743060', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/94cad1c8a786c9170f73267bc33d70cf3bc7577b', 'description': '网球花(学名：Haemanthus multiflorus Martyn)是石蒜科，网球花属多年生草本植物。鳞茎球形，叶片长圆形，叶柄短，鞘状。花茎直立，实心，高可达90厘米，先叶抽出，淡绿色或有红斑；伞形花序具多花，花红色；花被管圆筒状，花被裂片线形，花丝红色，伸出花被之外，花药黄色。浆果鲜红色。夏季开花。该种原产非洲热带。中国引种栽培供观赏。(概述图片参考来源：中国自然标本馆)'}}], 'log_id': 1510528898631779938}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "花朵识别\n",
    "'''\n",
    "\n",
    "request_url = \" https://aip.baidubce.com/rest/2.0/image-classify/v1/plant\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('yujinxiang.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2.酬载准备\n",
    "payload = {\n",
    "    \"access_token\":shena_AT,\n",
    "    \"image\":img,\n",
    "    \"baike_num\":5\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46074b7c",
   "metadata": {},
   "source": [
    "用户需求：如今的儿童较少深入感受大自然，在应试教育的培养下成长起来的大部分家长甚至连一些在老一辈看来最基础的植物都不甚了解。希望通过植物识别的方法帮助儿童、青少年扩宽对大自然的知识面，深入感受大自然。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4808e03",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
